<?php 	namespace Admin\Controller;
class BrandController extends CommonController
{
	protected $db;
	public function __init()
	{
		$this->db = new \Common\Model\Brand;
	}
	public function index()
	{
		$data = $this->db->orderBy("brand_sort","DESC")->get();
//		p($data);die;
		View::with("data",$data);
		View::make();
	}
	public function add()
	{
		if(IS_POST)
		{
			if(!$this->db->store())
			{
				View::error($this->db->getError());
			}else{
				View::success("添加成功",U('Brand/index'));
			}
		}
		View::make();
	}
	public function edit()
	{
		$brand_id = Q("get.brand_id",0,"intval");
		$oldData = $this->db->where("brand_id",$brand_id)->first();
		View::with("oldData",$oldData);
		if(IS_POST)
		{
			if(!$this->db->edit())
		{
			View::error($this->db->getError());
		}else
			{
				View::success("编辑成功",U('index'));
			}
		}
		
		View::make();
	}
	public function del()
	{
		$brand_id = Q("get.brand_id",0,"intval");
		$this->db->where("brand_id",$brand_id)->delete();
		View::success("删除成功",U('index'));
	}
}
